/**
 * This file is part of XaMauLo 
 * File :                       SchemaXML.scala
 * Author's email :             laure.conte@gmail.com
 *                              sophie.couillez@gmail.com
 **/


package objects;
import scala.xml._;
import scala._;
import scala.collection.mutable.HashMap;

/**
  *This class defines an Element of the XML files
 */

class Element(nomBal:String, container:String, lesFils:List[String], lesParents:List[String],attributs : HashMap[String,String],lig:int,colum:int) {

  val nameBalise:String = nomBal
  var sons:List[String] = lesFils
  var parents:List[String] = lesParents
  val contain:String = container
  val atts : HashMap[String,String]=attributs
  val ligne : int=lig
  val column : int=colum
  //add an element in the list of sons
  def addSon(son:String):Unit = {
    sons=son :: sons
  }
  
  //add an element in the list of parents
  def addParent(dad:String):Unit = {
    parents=dad :: parents
  }
  
  /*val typeElmt:List[String] = contain match {
    case null => List("node")
    case "" => List("node")
    case c @ Seq(c1, c2, y1, y2, '-', m1, m2, '-', d1, d2) if validChiffres(List(c1, c2, y1, y2, m1, m2, d1, d2)) => List("xs:date")
    case c @ Seq(c1, c2, y1, y2, '-', m1, m2, '-', d1, d2, h1, h2, ':', mm1, mm2, ':', s1, s2) if validChiffres(List(c1, c2, y1, y2, m1, m2, d1, d2, h1, h2, mm1, mm2, s1, s2)) => List("xs:dateTime")
    case c @ Seq(h1, h2, ':', m1, m2, ':', s1, s2, s3, s4, s5) if validChiffres(List(h1, h2, m1, m2, s1, s2, s3, s4, s5)) => List("xs:dateTime")
    case c @ Seq(c1, c2, y1, y2) if validChiffres(List(c1, c2, y1, y2)) => List("xs:gYear")
    case c @ Seq('-', '-', m1, m2, '-', d1, d2) if validChiffres(List(m1, m2, d1, d2)) => List("xs:gMonthDay")
    case c @ Seq('-', '-', '-', d1, d2) if validChiffres(List(d1, d2)) => List("xs:gDay")
    case c @ Seq('-', '-', m1, m2, '-', '-') if validChiffres(List(m1, m2)) => List("xs:gMonth")
    case c @ Seq(c1, c2, y1, y2, '-', m1, m2) if validChiffres(List(c1, c2, y1, y2, m1, m2)) => List("xs:gYearMonth")
    case Seq('0') => List("xs:decimal", "xs:integer", "xs:nonPositiveInteger", "xs:nonNegativeInteger", "xs:boolean")
    case Seq('1') => List("xs:decimal", "xs:integer", "xs:nonPositiveInteger", "xs:nonNegativeInteger", "xs:boolean")
    case c @ Seq( _* ) if validChiffres(c.toList) => List("xs:decimal", "xs:integer", "xs:nonNegativeInteger")
    case Seq('+', c @ _* ) if validChiffres(c.toList) => List("xs:decimal", "xs:integer", "xs:nonNegativeInteger", "xs:positiveInteger")
    case Seq('-', c @ _* ) if validChiffres(c.toList) => List("xs:decimal", "xs:integer", "xs:nonPositiveInteger", "xs:negativeInteger")
    //case Seq(c1 @ _*, '.', c2 @ _* ) if validChiffres(c1.toList ::: c2.toList) => List("xs:float", "xs:double")
    case c @ Seq('t', 'r', 'u', 'e') => List("xs:boolean") 
    case c @ Seq('f', 'a', 'l', 's', 'e') => List("xs:boolean")
    case c => List("xs:string")    
  }
  
  def validChiffres(listeChiffres:List[char]):Boolean = listeChiffres.length match {
    case 0 => return true
    case _ => listeChiffres.head match {
      case '1' => return validChiffres(listeChiffres.tail)
      case '2' => return validChiffres(listeChiffres.tail) 
      case '3' => return validChiffres(listeChiffres.tail)
      case '4' => return validChiffres(listeChiffres.tail)
      case '5' => return validChiffres(listeChiffres.tail)
      case '6' => return validChiffres(listeChiffres.tail)
      case '7' => return validChiffres(listeChiffres.tail)
      case '8' => return validChiffres(listeChiffres.tail)
      case '9' => return validChiffres(listeChiffres.tail)
      case _ => return false
    }
  }
  
  def stringToList(chaine:String):List[char] = {
    val s: Seq[Char] = chaine
    return s.toList
  }*/
}


